package club.babyf.nativeai.demo.list;

import java.util.ArrayList;
import java.util.List;

/**
 * SubList.
 *
 * @author zhanglei.
 * @date 2025/3/27 11:31.
 * @description 子列表.
 */
public class SubList {

    public static void main(String[] args) {
        List<String> sourceList = new ArrayList<>() {{
            add("H");
            add("O");
            add("L");
            add("L");
            add("I");
            add("S");
        }};

        List<String> subList = sourceList.subList(2, 5);

        System.out.println("sourceList ： " + sourceList);
        System.out.println("sourceList.subList(2, 5)得到List ： ");
        System.out.println("subList ： " + subList);

        sourceList.add("666");

        System.out.println("sourceList.add(666) 得到List ： ");
        System.out.println("sourceList : " + sourceList);
        System.out.println("subList : " + subList);

        // --------------------------------------------------------------------------------------------- //
        subList = new ArrayList<>(subList);
        System.out.println("subList = new ArrayList<>(subList) 得到List ： " + subList);
    }

}
